package com.zhuiyun.project.api.timepool.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.timepool.entity.TimePool;
import com.zhuiyun.project.api.timepool.mapper.TimePoolMapper;
import com.zhuiyun.project.api.timepool.service.TimePoolService;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import com.zhuiyun.project.utils.pageUtil.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName TimePoolController
 * @Description TODO
 * @Author wuwan
 * @Date 2023/12/18 10:57
 **/
@RestController
@Api(tags = "时间池")
@RequestMapping("/TimePool")
@Slf4j
public class TimePoolController {
    @Autowired
    TimePoolService timePoolService;
    @Resource
    TimePoolMapper timePoolMapper;

    /*
    * @Author xy
    * @Description todo 时间池添加和修改
    * @Date 2023/12/18 14:29
    * @Return
    * @param
    */
    @PostMapping("/addTimePool")
    @ApiOperation("时间池添加和修改")
    @OptLog(modular = "课程管理", type = CommonConstants.ADD, describe = "时间池添加和修改")
    public CommonResult SaveUpdateTimePool(TimePool timePool, String  startTime, String  endTime){
        boolean b = timePoolService.SaveUpdateTimePool(timePool, startTime, endTime);
        if (b){
            return CommonResult.ok("操作成功");
        }else{
            return CommonResult.error("操作失败");
        }
    }

    /*
    * @Author xy
    * @Description todo 分页查询时间池
    * @Date 2023/12/18 15:36
    * @Return
    * @param
    */
    @GetMapping("/selectTimePool")
    @ApiOperation("分页查询时间池")
    @OptLog(modular = "课程管理", type = CommonConstants.SELECT, describe = "分页查询时间池")
    public CommonResult selectTimePool(PageRequest pageRequest,String venueUniqueIdentifier){
        MybatisPageHelper.startPage(pageRequest);
        QueryWrapper<TimePool> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("venue_unique_identifier",venueUniqueIdentifier);
        queryWrapper.eq("del_flag","0");
//        queryWrapper.eq("status","0");
        List<TimePool> timePools = timePoolMapper.selectList(queryWrapper);
        PageResult pageResult = MybatisPageHelper.getPageResult(timePools);
        return CommonResult.ok(pageResult);
    }

    /*
    * @Author xy
    * @Description todo 时间池状态修改（0启用,1禁用）
    * @Date 2023/12/21 8:27
    * @Return
    * @param
    */
    @PostMapping("/updateTimePoolStatus")
    @ApiOperation("时间池状态修改")
    @OptLog(modular = "课程管理", type = CommonConstants.UPDATE, describe = "时间池状态修改")
    public CommonResult updateTimePoolStatus(@RequestBody TimePool timePool){
        timePoolMapper.updatescope(timePool);
        return CommonResult.ok("操作成功");
    }

    /*
    * @Author xy
    * @Description todo 时间池逻辑删除
    * @Date 2023/12/21 9:32
    * @Return
    * @param
    */
    @DeleteMapping("/{id}")
    @ApiOperation("时间池逻辑删除")
    @OptLog(modular = "课程管理", type = CommonConstants.DELETE, describe = "时间池逻辑删除")
    public CommonResult deleteTimePool(@PathVariable Integer id){
        timePoolMapper.deleteTimePool(id);
        return CommonResult.ok("操作成功");
    }

    /*
    * @Author xy
    * @Description todo 时间下拉框
    * @Date 2023/12/21 16:31
    * @Return
    * @param
    */
    @GetMapping("/selectTimePoolList")
    @ApiOperation("时间下拉框")
    @OptLog(modular = "课程管理", type = CommonConstants.SELECT, describe = "时间下拉框")
    public CommonResult selectTimePoolList(String venueUniqueIdentifier){
        QueryWrapper<TimePool> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("venue_unique_identifier",venueUniqueIdentifier);
        queryWrapper.eq("del_flag","0");
        queryWrapper.eq("status","0");
        List<TimePool> timePools = timePoolMapper.selectList(queryWrapper);
        return CommonResult.ok(timePools);
    }
}
